package o;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.Fragment.a;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.PrintWriter;
import java.util.ArrayList;
import FragmentTransaction.b;
import o.kp.c;

public final class jt extends FragmentTransaction implements d {
    boolean ˊ;
    final kd ˏ;
    public int ॱ = -1;

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder(DnsConfig.MAX_CACHE_ENTRIES);
        stringBuilder.append("BackStackEntry{");
        stringBuilder.append(Integer.toHexString(System.identityHashCode(this)));
        if (this.ॱ >= 0) {
            stringBuilder.append(" #");
            stringBuilder.append(this.ॱ);
        }
        if (this.ॱˊ != null) {
            stringBuilder.append(HwAccountConstants.BLANK);
            stringBuilder.append(this.ॱˊ);
        }
        stringBuilder.append("}");
        return stringBuilder.toString();
    }

    public void ˊ(String str, PrintWriter printWriter) {
        ॱ(str, printWriter, true);
    }

    public void ॱ(String str, PrintWriter printWriter, boolean z) {
        if (z) {
            printWriter.print(str);
            printWriter.print("mName=");
            printWriter.print(this.ॱˊ);
            printWriter.print(" mIndex=");
            printWriter.print(this.ॱ);
            printWriter.print(" mCommitted=");
            printWriter.println(this.ˊ);
            if (this.ʻ != 0) {
                printWriter.print(str);
                printWriter.print("mTransition=#");
                printWriter.print(Integer.toHexString(this.ʻ));
                printWriter.print(" mTransitionStyle=#");
                printWriter.println(Integer.toHexString(this.ʽ));
            }
            if (!(this.ˎ == 0 && this.ᐝ == 0)) {
                printWriter.print(str);
                printWriter.print("mEnterAnim=#");
                printWriter.print(Integer.toHexString(this.ˎ));
                printWriter.print(" mExitAnim=#");
                printWriter.println(Integer.toHexString(this.ᐝ));
            }
            if (!(this.ॱॱ == 0 && this.ʼ == 0)) {
                printWriter.print(str);
                printWriter.print("mPopEnterAnim=#");
                printWriter.print(Integer.toHexString(this.ॱॱ));
                printWriter.print(" mPopExitAnim=#");
                printWriter.println(Integer.toHexString(this.ʼ));
            }
            if (!(this.ˏॱ == 0 && this.ͺ == null)) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbTitleRes=#");
                printWriter.print(Integer.toHexString(this.ˏॱ));
                printWriter.print(" mBreadCrumbTitleText=");
                printWriter.println(this.ͺ);
            }
            if (!(this.ʻॱ == 0 && this.ॱˎ == null)) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbShortTitleRes=#");
                printWriter.print(Integer.toHexString(this.ʻॱ));
                printWriter.print(" mBreadCrumbShortTitleText=");
                printWriter.println(this.ॱˎ);
            }
        }
        if (!this.ˋ.isEmpty()) {
            printWriter.print(str);
            printWriter.println("Operations:");
            int size = this.ˋ.size();
            for (int i = 0; i < size; i++) {
                String str2;
                b bVar = (b) this.ˋ.get(i);
                switch (bVar.ˊ) {
                    case 0:
                        str2 = "NULL";
                        break;
                    case 1:
                        str2 = "ADD";
                        break;
                    case 2:
                        str2 = "REPLACE";
                        break;
                    case 3:
                        str2 = "REMOVE";
                        break;
                    case 4:
                        str2 = "HIDE";
                        break;
                    case 5:
                        str2 = "SHOW";
                        break;
                    case 6:
                        str2 = "DETACH";
                        break;
                    case 7:
                        str2 = "ATTACH";
                        break;
                    case 8:
                        str2 = "SET_PRIMARY_NAV";
                        break;
                    case 9:
                        str2 = "UNSET_PRIMARY_NAV";
                        break;
                    case 10:
                        str2 = "OP_SET_MAX_LIFECYCLE";
                        break;
                    default:
                        str2 = "cmd=" + bVar.ˊ;
                        break;
                }
                printWriter.print(str);
                printWriter.print("  Op #");
                printWriter.print(i);
                printWriter.print(": ");
                printWriter.print(str2);
                printWriter.print(HwAccountConstants.BLANK);
                printWriter.println(bVar.ॱ);
                if (z) {
                    if (!(bVar.ˋ == 0 && bVar.ˎ == 0)) {
                        printWriter.print(str);
                        printWriter.print("enterAnim=#");
                        printWriter.print(Integer.toHexString(bVar.ˋ));
                        printWriter.print(" exitAnim=#");
                        printWriter.println(Integer.toHexString(bVar.ˎ));
                    }
                    if (bVar.ˏ != 0 || bVar.ॱॱ != 0) {
                        printWriter.print(str);
                        printWriter.print("popEnterAnim=#");
                        printWriter.print(Integer.toHexString(bVar.ˏ));
                        printWriter.print(" popExitAnim=#");
                        printWriter.println(Integer.toHexString(bVar.ॱॱ));
                    }
                }
            }
        }
    }

    public jt(kd kdVar) {
        this.ˏ = kdVar;
    }

    void ˎ(int i, Fragment fragment, @Nullable String str, int i2) {
        super.ˎ(i, fragment, str, i2);
        fragment.ˊᐝ = this.ˏ;
    }

    @NonNull
    public FragmentTransaction ˊ(@NonNull Fragment fragment) {
        if (fragment.ˊᐝ == null || fragment.ˊᐝ == this.ˏ) {
            return super.ˊ(fragment);
        }
        throw new IllegalStateException("Cannot remove Fragment attached to a different FragmentManager. Fragment " + fragment.toString() + " is already attached to a FragmentManager.");
    }

    @NonNull
    public FragmentTransaction ॱ(@NonNull Fragment fragment) {
        if (fragment.ˊᐝ == null || fragment.ˊᐝ == this.ˏ) {
            return super.ॱ(fragment);
        }
        throw new IllegalStateException("Cannot hide Fragment attached to a different FragmentManager. Fragment " + fragment.toString() + " is already attached to a FragmentManager.");
    }

    @NonNull
    public FragmentTransaction ˏ(@NonNull Fragment fragment) {
        if (fragment.ˊᐝ == null || fragment.ˊᐝ == this.ˏ) {
            return super.ˏ(fragment);
        }
        throw new IllegalStateException("Cannot show Fragment attached to a different FragmentManager. Fragment " + fragment.toString() + " is already attached to a FragmentManager.");
    }

    @NonNull
    public FragmentTransaction ˋ(@NonNull Fragment fragment) {
        if (fragment.ˊᐝ == null || fragment.ˊᐝ == this.ˏ) {
            return super.ˋ(fragment);
        }
        throw new IllegalStateException("Cannot detach Fragment attached to a different FragmentManager. Fragment " + fragment.toString() + " is already attached to a FragmentManager.");
    }

    @NonNull
    public FragmentTransaction ˏ(@NonNull Fragment fragment, @NonNull c cVar) {
        if (fragment.ˊᐝ != this.ˏ) {
            throw new IllegalArgumentException("Cannot setMaxLifecycle for Fragment not attached to FragmentManager " + this.ˏ);
        } else if (cVar.ˏ(c.CREATED)) {
            return super.ˏ(fragment, cVar);
        } else {
            throw new IllegalArgumentException("Cannot set maximum Lifecycle below " + c.CREATED);
        }
    }

    public void ˏ(int i) {
        if (this.ˋॱ) {
            if (kd.ˎ) {
                Log.v("FragmentManager", "Bump nesting in " + this + " by " + i);
            }
            int size = this.ˋ.size();
            for (int i2 = 0; i2 < size; i2++) {
                b bVar = (b) this.ˋ.get(i2);
                if (bVar.ॱ != null) {
                    Fragment fragment = bVar.ॱ;
                    fragment.ˋˊ += i;
                    if (kd.ˎ) {
                        Log.v("FragmentManager", "Bump nesting of " + bVar.ॱ + " to " + bVar.ॱ.ˋˊ);
                    }
                }
            }
        }
    }

    public void ॱ() {
        if (this.ʾ != null) {
            for (int i = 0; i < this.ʾ.size(); i++) {
                ((Runnable) this.ʾ.get(i)).run();
            }
            this.ʾ = null;
        }
    }

    public int ˏ() {
        return ˊ(false);
    }

    public int ˋ() {
        return ˊ(true);
    }

    public void ˊ() {
        ʻ();
        this.ˏ.ˋ((d) this, true);
    }

    int ˊ(boolean z) {
        if (this.ˊ) {
            throw new IllegalStateException("commit already called");
        }
        if (kd.ˎ) {
            Log.v("FragmentManager", "Commit: " + this);
            PrintWriter printWriter = new PrintWriter(new gy("FragmentManager"));
            ˊ("  ", printWriter);
            printWriter.close();
        }
        this.ˊ = true;
        if (this.ˋॱ) {
            this.ॱ = this.ˏ.ॱ(this);
        } else {
            this.ॱ = -1;
        }
        this.ˏ.ˏ((d) this, z);
        return this.ॱ;
    }

    public boolean ॱ(ArrayList<jt> arrayList, ArrayList<Boolean> arrayList2) {
        if (kd.ˎ) {
            Log.v("FragmentManager", "Run: " + this);
        }
        arrayList.add(this);
        arrayList2.add(Boolean.valueOf(false));
        if (this.ˋॱ) {
            this.ˏ.ˎ(this);
        }
        return true;
    }

    boolean ˋ(int i) {
        int size = this.ˋ.size();
        for (int i2 = 0; i2 < size; i2++) {
            b bVar = (b) this.ˋ.get(i2);
            int i3 = bVar.ॱ != null ? bVar.ॱ.ˍ : 0;
            if (i3 != 0 && i3 == i) {
                return true;
            }
        }
        return false;
    }

    boolean ॱ(ArrayList<jt> arrayList, int i, int i2) {
        if (i2 == i) {
            return false;
        }
        int size = this.ˋ.size();
        int i3 = -1;
        int i4 = 0;
        while (i4 < size) {
            int i5;
            b bVar = (b) this.ˋ.get(i4);
            int i6 = bVar.ॱ != null ? bVar.ॱ.ˍ : 0;
            if (i6 == 0 || i6 == i3) {
                i5 = i3;
            } else {
                for (int i7 = i; i7 < i2; i7++) {
                    jt jtVar = (jt) arrayList.get(i7);
                    int size2 = jtVar.ˋ.size();
                    for (int i8 = 0; i8 < size2; i8++) {
                        b bVar2 = (b) jtVar.ˋ.get(i8);
                        if (bVar2.ॱ != null) {
                            i3 = bVar2.ॱ.ˍ;
                        } else {
                            i3 = 0;
                        }
                        if (i3 == i6) {
                            return true;
                        }
                    }
                }
                i5 = i6;
            }
            i4++;
            i3 = i5;
        }
        return false;
    }

    void ˎ() {
        int size = this.ˋ.size();
        for (int i = 0; i < size; i++) {
            b bVar = (b) this.ˋ.get(i);
            Fragment fragment = bVar.ॱ;
            if (fragment != null) {
                fragment.ˊ(this.ʻ, this.ʽ);
            }
            switch (bVar.ˊ) {
                case 1:
                    fragment.ˎ(bVar.ˋ);
                    this.ˏ.ॱ(fragment, false);
                    break;
                case 3:
                    fragment.ˎ(bVar.ˎ);
                    this.ˏ.ˏॱ(fragment);
                    break;
                case 4:
                    fragment.ˎ(bVar.ˎ);
                    this.ˏ.ॱˊ(fragment);
                    break;
                case 5:
                    fragment.ˎ(bVar.ˋ);
                    this.ˏ.ᐝॱ(fragment);
                    break;
                case 6:
                    fragment.ˎ(bVar.ˎ);
                    this.ˏ.ॱˎ(fragment);
                    break;
                case 7:
                    fragment.ˎ(bVar.ˋ);
                    this.ˏ.ʻॱ(fragment);
                    break;
                case 8:
                    this.ˏ.ʽॱ(fragment);
                    break;
                case 9:
                    this.ˏ.ʽॱ(null);
                    break;
                case 10:
                    this.ˏ.ˋ(fragment, bVar.ʻ);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + bVar.ˊ);
            }
            if (!(this.ॱᐝ || bVar.ˊ == 1 || fragment == null)) {
                this.ˏ.ˊॱ(fragment);
            }
        }
        if (!this.ॱᐝ) {
            this.ˏ.ॱ(this.ˏ.ͺ, true);
        }
    }

    void ˏ(boolean z) {
        for (int size = this.ˋ.size() - 1; size >= 0; size--) {
            b bVar = (b) this.ˋ.get(size);
            Fragment fragment = bVar.ॱ;
            if (fragment != null) {
                fragment.ˊ(kd.ˋ(this.ʻ), this.ʽ);
            }
            switch (bVar.ˊ) {
                case 1:
                    fragment.ˎ(bVar.ॱॱ);
                    this.ˏ.ˏॱ(fragment);
                    break;
                case 3:
                    fragment.ˎ(bVar.ˏ);
                    this.ˏ.ॱ(fragment, false);
                    break;
                case 4:
                    fragment.ˎ(bVar.ˏ);
                    this.ˏ.ᐝॱ(fragment);
                    break;
                case 5:
                    fragment.ˎ(bVar.ॱॱ);
                    this.ˏ.ॱˊ(fragment);
                    break;
                case 6:
                    fragment.ˎ(bVar.ˏ);
                    this.ˏ.ʻॱ(fragment);
                    break;
                case 7:
                    fragment.ˎ(bVar.ॱॱ);
                    this.ˏ.ॱˎ(fragment);
                    break;
                case 8:
                    this.ˏ.ʽॱ(null);
                    break;
                case 9:
                    this.ˏ.ʽॱ(fragment);
                    break;
                case 10:
                    this.ˏ.ˋ(fragment, bVar.ʽ);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + bVar.ˊ);
            }
            if (!(this.ॱᐝ || bVar.ˊ == 3 || fragment == null)) {
                this.ˏ.ˊॱ(fragment);
            }
        }
        if (!this.ॱᐝ && z) {
            this.ˏ.ॱ(this.ˏ.ͺ, true);
        }
    }

    Fragment ˋ(ArrayList<Fragment> arrayList, Fragment fragment) {
        int i = 0;
        while (i < this.ˋ.size()) {
            b bVar = (b) this.ˋ.get(i);
            switch (bVar.ˊ) {
                case 1:
                case 7:
                    arrayList.add(bVar.ॱ);
                    break;
                case 2:
                    Fragment fragment2 = bVar.ॱ;
                    int i2 = fragment2.ˍ;
                    Object obj = null;
                    int size = arrayList.size() - 1;
                    Fragment fragment3 = fragment;
                    int i3 = i;
                    while (size >= 0) {
                        Object obj2;
                        Fragment fragment4 = (Fragment) arrayList.get(size);
                        if (fragment4.ˍ != i2) {
                            obj2 = obj;
                        } else if (fragment4 == fragment2) {
                            obj2 = 1;
                        } else {
                            if (fragment4 == fragment3) {
                                this.ˋ.add(i3, new b(9, fragment4));
                                i3++;
                                fragment3 = null;
                            }
                            b bVar2 = new b(3, fragment4);
                            bVar2.ˋ = bVar.ˋ;
                            bVar2.ˏ = bVar.ˏ;
                            bVar2.ˎ = bVar.ˎ;
                            bVar2.ॱॱ = bVar.ॱॱ;
                            this.ˋ.add(i3, bVar2);
                            arrayList.remove(fragment4);
                            i3++;
                            obj2 = obj;
                        }
                        size--;
                        obj = obj2;
                    }
                    if (obj != null) {
                        this.ˋ.remove(i3);
                        i3--;
                    } else {
                        bVar.ˊ = 1;
                        arrayList.add(fragment2);
                    }
                    i = i3;
                    fragment = fragment3;
                    break;
                case 3:
                case 6:
                    arrayList.remove(bVar.ॱ);
                    if (bVar.ॱ != fragment) {
                        break;
                    }
                    this.ˋ.add(i, new b(9, bVar.ॱ));
                    i++;
                    fragment = null;
                    break;
                case 8:
                    this.ˋ.add(i, new b(9, fragment));
                    i++;
                    fragment = bVar.ॱ;
                    break;
                default:
                    break;
            }
            i++;
        }
        return fragment;
    }

    Fragment ˎ(ArrayList<Fragment> arrayList, Fragment fragment) {
        int size = this.ˋ.size() - 1;
        Fragment fragment2 = fragment;
        while (size >= 0) {
            Fragment fragment3;
            b bVar = (b) this.ˋ.get(size);
            switch (bVar.ˊ) {
                case 1:
                case 7:
                    arrayList.remove(bVar.ॱ);
                    fragment3 = fragment2;
                    continue;
                case 3:
                case 6:
                    arrayList.add(bVar.ॱ);
                    fragment3 = fragment2;
                    continue;
                case 8:
                    fragment3 = null;
                    continue;
                case 9:
                    fragment3 = bVar.ॱ;
                    continue;
                case 10:
                    bVar.ʻ = bVar.ʽ;
                    break;
            }
            fragment3 = fragment2;
            size--;
            fragment2 = fragment3;
        }
        return fragment2;
    }

    boolean ʼ() {
        for (int i = 0; i < this.ˋ.size(); i++) {
            if (ˎ((b) this.ˋ.get(i))) {
                return true;
            }
        }
        return false;
    }

    void ˏ(a aVar) {
        for (int i = 0; i < this.ˋ.size(); i++) {
            b bVar = (b) this.ˋ.get(i);
            if (ˎ(bVar)) {
                bVar.ॱ.ˋ(aVar);
            }
        }
    }

    private static boolean ˎ(b bVar) {
        Fragment fragment = bVar.ॱ;
        return (fragment == null || !fragment.ᐝॱ || fragment.ॱʼ == null || fragment.ˋᐝ || fragment.ˋˋ || !fragment.ʻˋ()) ? false : true;
    }

    @Nullable
    public String ॱॱ() {
        return this.ॱˊ;
    }

    public boolean ʽ() {
        return this.ˋ.isEmpty();
    }
}
